home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 201 / 201.xpi / modules / loggedprompter.jsm < prev    next >
Encoding:
Text File  |  2010-01-11  |  2.6 KB  |  92 lines

  1. /* You may find the license in the LICENSE file */
  2.  
  3. const EXPORTED_SYMBOLS = ['LoggedPrompter'];
  4.  
  5. const Cc = Components.classes;
  6. const Ci = Components.interfaces;
  7. const Cr = Components.results;
  8. const Cu = Components.utils;
  9. const module = Cu.import;
  10. const Exception = Components.Exception;
  11.  
  12. module("resource://gre/modules/XPCOMUtils.jsm");
  13. module("resource://dta/utils.jsm");
  14.  
  15. function setNewGetter(aObject, aName, aLambda) {
  16.     if (aName in aObject) {
  17.         throw new Exception(aName + " is already defined in context " + aObject);
  18.     }
  19.     try {
  20.         aObject.__defineGetter__(aName, function() {
  21.             delete aObject[aName];
  22.             return aObject[aName] = aLambda.apply(aObject);
  23.         });
  24.  
  25.     }
  26.     catch (ex) {
  27.         log(aName);
  28.         log(ex);
  29.     }
  30. }
  31.  
  32. function ServiceGetter(context, name, contract, iface) {
  33.     if (!iface) {
  34.         iface = Ci.nsISupports;
  35.     }
  36.     else if (typeof iface == "string") {
  37.         iface = Ci[iface];
  38.     }
  39.     setNewGetter(
  40.         context,
  41.         name,
  42.         function() {
  43.             try {
  44.                 return Cc[contract].getService(iface);
  45.             }
  46.             catch (ex) {
  47.                 log(ex);
  48.                 log(contract);
  49.                 log(iface);
  50.                 throw ex;
  51.             }
  52.         }
  53.     );    
  54. }
  55.  
  56. ServiceGetter(this, "WindowWatcherService", "@mozilla.org/embedcomp/window-watcher;1", "nsIWindowWatcher");
  57. ServiceGetter(this, "Debug", "@downthemall.net/debug-service;1", "dtaIDebugService");
  58.  
  59. function LoggedPrompter(window) {
  60.     setNewGetter(
  61.         this,
  62.         'authPrompter',
  63.         function() {
  64.             return WindowWatcherService
  65.                 .getNewAuthPrompter(window)
  66.                 .QueryInterface(Ci.nsIAuthPrompt);
  67.         }
  68.     );
  69.  
  70.     setNewGetter(
  71.         this,
  72.         'prompter',
  73.         function() {
  74.             let _p = WindowWatcherService
  75.                 .getNewPrompter(window)
  76.                 .QueryInterface(Ci.nsIPrompt);        
  77.             let _dp = {
  78.                 QueryInterface: XPCOMUtils.generateQI([Ci.nsIPrompt]),
  79.                 alert: function(title, text) Debug.log(text, title),
  80.                 alertCheck: function(title, text, cm, cv) Debug.log(text, title),
  81.                 confirm: function(title, text) _p.confirm(title, text),
  82.                 confirmCheck: function(title, text, cm, cv) _p.confirmCheck(title, text, cm, cv),
  83.                 confirmEx: function(title, text, bflags, bt0, bt1, bt2, cm, cv) _p.confirmEx(title, text, bflags, bt0, bt1, bt2, cm, cv),
  84.                 prompt: function(title, text, value, cm, cv) _p.prompt(title, text, value, cm, cv),
  85.                 promptPassword: function(title, text, password, cm, cv) _p.promptPassword(title, text, password, cm, cv),
  86.                 promptUsernameAndPassword: function(title, text, un, pw, cm, cv) _p.promptUsernameAndPassword(title, text, un, pw, cm, cv),
  87.                 select: function(title, text, count, list, selection) _p.select(title, text, count, list, selection)
  88.             }
  89.             return _dp;
  90.         }
  91.     );    
  92. }